public class MyQueue2 {
    static class Node{
        public int val;
        public Node prev;
        public Node next;

        public Node(int val) {
            this.val = val;
        }
    }
    public Node head;
    public Node last;
    public int usedSize;

    public void offer(int data){
        Node node = new Node(data);
        if(head == null){
            last = node;
        }else{
            node.next = head;
            head.prev = node;
        }
        head = node;
        usedSize++;
    }

    public int poll(){
        if(empty()){
            throw new EmptyQueueException("队列为空，出队列失败！");
        }
        int ret = last.val;
        if(last == head){
            last = null;
            head = null;
        }else{
            last = last.prev;
            last.next.prev = null;
            last.next = null;
        }
        usedSize--;
        return ret;
    }

    public int getUsedSize(){
        return usedSize;
    }
    public boolean empty(){
        return usedSize == 0;
    }

    public int peek(){
        return  last.val;
    }
}
